package com.jett.mycloud.exp;

import com.jett.mycloud.resp.ResultData;
import com.jett.mycloud.resp.ReturnCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : 王雪峰
 * @description: TODO
 * @date : 2024/3/4 9:00
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResultData<String> exception(Exception e){
        log.error("*************全局异常处理模块*************");
        log.error("错误码:{}",ReturnCodeEnum.RC500.getCode());
        log.error("异常信息:{}",e.getMessage());
        log.error("*************=============*************");
        return ResultData.fail(ReturnCodeEnum.RC500.getCode(),e.getMessage());
    }
}
